package com.mmdccj.yugu.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mmdccj.yugu.entity.SingerInfo;
import com.mmdccj.yugu.entity.User;
import com.mmdccj.yugu.mapper.SingerInfoMapper;
import com.mmdccj.yugu.service.SingerInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Random;

/**
 * @Author: MMDCCJ
 * @date: 2023-12-08 21:42
 */
@Slf4j
@Service
public class SingerInfoServiceImpl implements SingerInfoService {
    // 自动注入SingerInfoMapper实例
    @Autowired
    private SingerInfoMapper singerInfoMapper;

    /**
     * 根据歌手ID获取歌手信息
     *
     * @param userId 歌手ID
     * @return SingerInfo 歌手信息
     */
    @Override
    public SingerInfo getSingerInfo(String userId) {
        return singerInfoMapper.getSingerInfo(userId);
    }

    @Override
    public PageInfo<User> random() {
        int sum = singerInfoMapper.getInfoNums();
        int max = sum / 6;
        Random random = new Random();
        int currentPage = random.nextInt() % max;
        PageHelper.startPage(currentPage, 6);
        return new PageInfo<>(singerInfoMapper.getAllSingerInfo());
    }
}
